package com.libweb.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.libweb.model.dao.BoardDao;
import com.libweb.model.dao.MemberDao;
import com.libweb.model.dto.Board;
import com.libweb.model.dto.Member;

@WebServlet("/board/replyform.action")
public class BoardReplyFormServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		//답글의 대상 글번호를 읽어서 변수에 저장
		//(대상 글번호는 boardview.jsp에서 전송된 데이터)
		if (req.getParameter("boardno") == null) {
			resp.sendRedirect("/libweb/board/list.action");
			return;
		}
		int number = Integer.parseInt(req.getParameter("boardno"));
		//답글  대상글의 번호로 데이터베이스에서 조회
		BoardDao dao = new BoardDao();
		Board board = dao.getBoardByBoardNo(number);
		//조회 실패하면 목록으로 이동
		if (board == null) {
			resp.sendRedirect("/libweb/board/list.action");
			return;			
		}
		req.setAttribute("board", board);
		
		//3. 목록 페이지로 이동
		RequestDispatcher dispatcher = 
			req.getRequestDispatcher("/WEB-INF/views/board/boardreplyform.jsp");

		dispatcher.forward(req, resp);
		
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






